#列表推导式的格式：[计算公式 for循环 if判断]

#列表推导式
#1.通过列表推导式快速创建[1, 11)所有数字的列表
lst = [ele for ele in range(1,11)]
print(lst)

#2.通过列表推导式快速创建[1, 11)所有偶数的列表
lst = [ele for ele in range(1,11) if ele % 2 == 0]
print(lst)

#3.通过列表推导式快速创建[1, 11)所有偶数的平方的列表
lst = [ele ** 2 for ele in range(1,11) if ele % 2 == 0]
print(lst)


#元组推导式
#1.元组推导式的格式:(计算公式 for循环 if判断)，其他与列表推导式一致
tp  =(ele for ele in range(1, 11))
print(tuple(tp))

ls = (ele ** 2 for ele in range(1,11) if ele % 2 == 0)
print(tuple(ls))

#集合推导式
#1.集合推导式的格式:{计算公式 for循环 if判断}，其他与列表推导式一致
an = {ele for ele in range(1,11)}
print(an)

#字典推导式
# {1:"1",2:"4",3:"9",5:"25"....9:"81"}
__dict = {ele:str(ele ** 2) for ele in range(1,11) if ele % 2 == 1}
print(__dict)

#2.zip
lst1 = ["张三","李四","王五"]
lst2 = [13,14,15]
#{"张三"：13,"李四"：14,"王五"：15}

__dict = {k:v for k,v in zip(lst1,lst2)}
print(__dict)

